<!-- UserModel.php-->
<?php 
	require 'ConnDB.php';
	require 'config.php';
	require 'Model.php';
	class VideoModel extends Model{
		function __Construct(){
			parent::__Construct();
		}
		function getVideoList(){
			$sql = 'select * from videos';
			$data = $this->conn->query($sql);
			//$this->conn = new ConnDB();
			return $data;
		}


		function getUserByID($id){
			$sql = "select * from videos where vid=".$id;
			$data = $this->conn->query($sql);
			return $data;
		}

		function Updatevideo($data){
			if(!empty($_FILES["pic"]["name"])){
  				$pic = parent::uploadfile('pic','images/',array('png','jpg','gif'));
  			}
		    else{
		  		$pic='';
		  	}
		  	$video = array(
				'vid' =>$_POST['vid'],
				'videoname' => $_POST['videoname'],
				'tid' => $_POST['tid'],
				'pic' => $pic,
				'intro' => $_POST['intro'],
				'uploaddate' => $_POST['uploaddate'],
				'uploadadmin' => $_POST['uploadadmin'],
				'hittimes' => $_POST['hittimes'],
				'downtimes' => $_POST['downtimes'],
				'address' => $_POST['address'],
				);
			$sql="update videos set vid='$video[vid]',videoname='$video[videoname]',tid='$video[tid]',pic='$video[pic]',intro='$video[intro]',uploaddate='$video[uploaddate]',uploadadmin='$video[uploadadmin]',hittimes='$video[hittimes]',downtimes='$video[downtimes]',address='$video[address]' where vid=".$video['vid'];
			//echo "$sql";
			$result = $this->conn->query($sql);
			return $result;
		}

		function addVideo($data){
			//var_dump($data);
			//如果选择了照片，则上传照片文件
			if(!empty($_FILES["pic"]["name"])){
  				$pic = parent::uploadfile('pic','images/',array('png','jpg','gif'));
  			}
		    else{
		  		$pic='';
		  	}
			$user = array(
				'vid' =>'',
				'videoname' => $data['videoname'],
				'tid' => $data['tid'],
				'pic' => $pic,
				'intro' => $data['intro'],
				'uploaddate' => $data['uploaddate'],
				'uploadadmin' => $data['uploadadmin'],
				'hittimes' => $data['hittimes'],
				'downtimes' => $data['downtimes'],
				'address' => $data['address']
				);
			$keys = implode(',',array_keys($user));
			$values = implode("','",array_values($user));
			/*$sql = "insert into users values ('$user[uid]','$user[uname]','$user[password]','$user[gender]','$user[birthdate]','$user[hobby]','$user[degree]','$user[intro]','$user[pic]')";*/
			$sql="insert into videos ({$keys}) VALUES ('{$values}')";
			//echo "$sql";
			$result = $this->conn->query($sql);
			return $result;
		}

		function Delvideo($id){
			$sql = "Delete from videos where vid=".$id;
			$data = $this->conn->query($sql);
			return $data;
		}
	}
 ?>